<?php

namespace App\Http\Controllers\Personal;
use Illuminate\Http\Request;
use Style;
/**
 * @param //用户表
 * 创建时间 2016-8-13
 **/
define("TOKEN", "weixin");

class WeChatController extends CommonController{
    private $WxObj;
    private $appID='wx8828e574d414819a';
    private $appsecret='3be1c50c92ec10c76c16c8981d886816';
    private $accessToken;

    /**
     * api
     * @param Request $request
     */
    public function api(Request $request){
        $token='personalweixin';
        //绑定
        $this->verify($token);
    }

    /**
     * 验证
     * @param $token
     * @return bool
     */
    private function verify($token){
        $echoStr = $_GET["echostr"];
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];
        $tmpArr = array($token, $timestamp, $nonce);
        // use SORT_STRING rule
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );
        if( $tmpStr == $signature && isset($_GET['echostr'])){
            echo $_GET['echostr'];
        }else{
            return false;
        }
    }
}